﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Tailor_CustomerSlip : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loadOrderDetails();
        }
    }

    private void loadOrderDetails()
    {
        string fromDate = DateTime.Parse(Request.QueryString["FromDate"].ToString()).ToString("yyyy-MM-dd ") + " 12:00 AM";
        string toDate = DateTime.Parse(Request.QueryString["ToDate"].ToString()).ToString("yyyy-MM-dd ") + " 11:59 PM";

        string sql = @"
            SELECT count(Tailor_OrderDetails.[OrderDetailsID]) as [TotalItem]
,Tailor_Order.[OrderID]
      ,Tailor_Order.[CustomerID]
      ,Tailor_Order.[TotalAmount]
      ,Tailor_Order.[FabricDue]
      ,Tailor_Order.[DesignCharge]
      ,Tailor_Order.[OrderDate]
      ,Tailor_Order.[TrialDate]
      ,Tailor_Order.[DelivaryDate]
      ,Tailor_Order.[OtherCharges]
      ,Tailor_Order.[Discount]
      ,Tailor_Order.[PaidAmount]
      ,Tailor_Order.[DueAmount]
      ,Tailor_Order.[ExtraField10]
      ,Tailor_Order.[ExtraField1]
      ,Tailor_Order.[ExtraField2]
      ,Tailor_Order.[ExtraField3]
      ,Tailor_Order.[ExtraField4]
      ,Tailor_Order.[ExtraField5]
      ,Tailor_Order.[ExtraField6]
      ,Tailor_Order.[ExtraField7]
      ,Tailor_Order.[ExtraField8]
      ,Tailor_Order.[ExtraField9]
      ,Tailor_Order.[WorkStationID]
      ,Tailor_Order.[RowStatusID]
      ,Tailor_Order.[AddedBy]
      ,Tailor_Order.[AddedDate]
      ,Tailor_Order.[UpdatedDate]
      ,Tailor_Order.[UpdatedBy]
,Pos_Customer.CustomerName
,Pos_Customer.Mobile
              FROM [Tailor_OrderDetails]
            inner join Tailor_Order on Tailor_Order.OrderID =Tailor_OrderDetails.[OrderID]
 inner join Pos_Customer on Pos_Customer.Pos_CustomerID = Tailor_Order.CustomerID
where Tailor_Order.[OrderDate] between '" + fromDate + @"' and '"+toDate+ @"'
            group by Tailor_Order.[OrderID]
      ,Tailor_Order.[CustomerID]
      ,Tailor_Order.[TotalAmount]
      ,Tailor_Order.[FabricDue]
      ,Tailor_Order.[DesignCharge]
      ,Tailor_Order.[OrderDate]
      ,Tailor_Order.[TrialDate]
      ,Tailor_Order.[DelivaryDate]
      ,Tailor_Order.[OtherCharges]
      ,Tailor_Order.[Discount]
      ,Tailor_Order.[PaidAmount]
      ,Tailor_Order.[DueAmount]
      ,Tailor_Order.[ExtraField10]
      ,Tailor_Order.[ExtraField1]
      ,Tailor_Order.[ExtraField2]
      ,Tailor_Order.[ExtraField3]
      ,Tailor_Order.[ExtraField4]
      ,Tailor_Order.[ExtraField5]
      ,Tailor_Order.[ExtraField6]
      ,Tailor_Order.[ExtraField7]
      ,Tailor_Order.[ExtraField8]
      ,Tailor_Order.[ExtraField9]
      ,Tailor_Order.[WorkStationID]
      ,Tailor_Order.[RowStatusID]
      ,Tailor_Order.[AddedBy]
      ,Tailor_Order.[AddedDate]
      ,Tailor_Order.[UpdatedDate]
      ,Tailor_Order.[UpdatedBy]
,Pos_Customer.CustomerName
,Pos_Customer.Mobile

order by Tailor_Order.[WorkStationID], Tailor_Order.[OrderDate] desc
";

        DataSet ds = CommonManager.SQLExec(sql);

        int subTotal_itemCount = 0;
        decimal subTotal_TotalAmount = 0;
        decimal subTotal_FabricDue = 0;
        decimal subTotal_DesignCharge = 0;
        decimal subTotal_OtherCharges = 0;
        decimal subTotal_Discount = 0;
        decimal subTotal_PaidAmount = 0;
        decimal subTotal_DueAmount = 0;
        decimal subTotal_PaymentCash = 0;
        decimal subTotal_PaymentCardDBBL = 0;
        decimal subTotal_PaymentCardCITY = 0;

        int total_itemCount = 0;
        decimal total_TotalAmount = 0;
        decimal total_FabricDue = 0;
        decimal total_DesignCharge = 0;
        decimal total_OtherCharges = 0;
        decimal total_Discount = 0;
        decimal total_PaidAmount = 0;
        decimal total_DueAmount = 0;
        decimal total_PaymentCash = 0;
        decimal total_PaymentCardDBBL = 0;
        decimal total_PaymentCardCITY = 0;


        int grandTotal_itemCount = 0;
        decimal grandTotal_TotalAmount = 0;
        decimal grandTotal_FabricDue = 0;
        decimal grandTotal_DesignCharge = 0;
        decimal grandTotal_OtherCharges = 0;
        decimal grandTotal_Discount = 0;
        decimal grandTotal_PaidAmount = 0;
        decimal grandTotal_DueAmount = 0;
        decimal grandTotal_PaymentCash = 0;
        decimal grandTotal_PaymentCardDBBL = 0;
        decimal grandTotal_PaymentCardCITY = 0;

        string workStationID = "";
        string date = "";
        /*
        foreach (DataRow dr in ds.Tables[0].Rows)
        {
            //if (workStationID == dr["WorkStationID"].ToString())
            //{ 
                
            //}


        }   
        */
        gvOrder.DataSource = ds.Tables[0];
        gvOrder.DataBind();
    }
}